package com.obtk.property.controller;

import com.github.pagehelper.Page;
import com.obtk.property.common.MessageComplaint;
import com.obtk.property.common.PageResult;
import com.obtk.property.common.Result;
import com.obtk.property.common.StatusCode;

import com.obtk.property.pojo.Complaint;
import com.obtk.property.service.ComplaintService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/complaint")
public class ComplaintController {

    @Autowired
    private ComplaintService complaintService;

    @RequestMapping("/find")
    public Result find(){
        List<Complaint> all= complaintService.findAll();
        return new Result(true,200,"请求成功",all);
    }
    @RequestMapping("/search")
    public PageResult search(@RequestBody Map searchMap){
        Page<Complaint> page = complaintService.search(searchMap);
        System.out.println(searchMap);
        return new PageResult(true, StatusCode.OK, MessageComplaint.Complaint_SEARCH_SUCCESS,page.getResult(),page.getTotal());
    }
    @RequestMapping("/add")
    public Result add(@RequestBody Complaint complaint){
        Boolean add = complaintService.add(complaint);
        return new Result(true, StatusCode.OK, MessageComplaint.Complaint_ADD_SUCCESS);
    }
    @RequestMapping("/findById")
    public Result findById(Integer complaintId){
        Complaint complaint = complaintService.findById(complaintId);
        return new Result(true, StatusCode.OK, MessageComplaint.Complaint_FIND_BY_ID_SUCCESS,complaint);
    }
    @RequestMapping("/update")
    public Result update(@RequestBody Complaint complaint){
        Boolean add = complaintService.update(complaint);
        return new Result(true, StatusCode.OK, MessageComplaint.Complaint_UPDATE_SUCCESS);
    }
    @RequestMapping("/updateStatus/{status}/{complaintId}")
    public Result updateStatus(@PathVariable("status") String status, @PathVariable("complaintId") Integer complaintId){
        Boolean flag = complaintService.updateStatus(status,complaintId);
        return new Result(true, StatusCode.OK, MessageComplaint.Complaint_UPDATE_STATUS_SUCCESS);
    }

    @RequestMapping("/del")
    public Result del(@RequestBody List<Integer> ids){
        Boolean flag = complaintService.del(ids);
        return new Result(true, StatusCode.OK, MessageComplaint.Complaint_DELETE_SUCCESS);
    }

}
